/** Luogu 3367 */
#include <stdio.h>
#include <stdbool.h>
#define maxn 200006
int par[maxn];
int rank(int i) {
  if(par[i]==i)return 1;
  else return 1+rank(par[i]);
}
int find(int x) {
  if(x == par[x]) return x;
  return par[x] = find(par[x]);
}
bool same(int x, int y) {
  return find(x) == find(y);
}
void unite(int x, int y) {
  if(same(x, y)) return;
  if(rank(x)<rank(y)) {
    int t=x;x=y;y=t;
  }
  y = find(y);
  par[y] = x;
}
void init() {
  for(int i=0; i<maxn; ++i) {
    par[i] = i;
  }
}
int n, m;
int main() {
  init();
  scanf("%d%d", &n, &m);
  for(int i=0; i<m; ++i) {
    int z, x, y; scanf("%d%d%d", &z, &x, &y);
    if(z==1) {
      unite(x, y);
    }
    else {
      putchar("NY"[same(x, y)]);
      putchar('\n');
    }
  }
}
